<?php

use App\Http\Controllers\Common\CommonController;
use App\Http\Controllers\OpenShop\Feishu\UserBaseInfoController;
use App\Http\Controllers\WorkOrder\FuYouController;
use App\Http\Controllers\WorkOrder\Merchant\AppraiseController;
use App\Http\Controllers\WorkOrder\Merchant\ProductSelectionProposalController;
use App\Http\Controllers\WorkOrder\Web\AppraiseController as WebAppraiseController;
use App\Http\Controllers\WorkOrder\ProblemFeedbackController;
use App\Http\Controllers\WorkOrder\Wap\FunctionOpenController;
use App\Http\Controllers\WorkOrder\Wap\MissionController;
use App\Http\Controllers\WorkOrder\Web\ApplyController;
use App\Http\Controllers\WorkOrder\Web\ProblemFeedbackWebController;
use App\Http\Controllers\WorkOrder\Web\ProductSelectionProposalWebController;
use App\Http\Controllers\WorkOrder\Web\WorkflowV2TypeController;
use App\Http\Middleware\OpenShop\MerchantAppAuth;
use Illuminate\Support\Facades\Route;
use App\Http\Middleware\OpenShop\FeishuWebAuth;
use App\Http\Middleware\OpenShop\UserPermissionAuth;
use App\Http\Controllers\WorkOrder\Web\WorkOrderController;
use App\Http\Middleware\Common\LockBefore;
use App\Http\Middleware\Common\LockAfter;

/**
 * 工单功能路由
 */

// 商家APP路由
Route::prefix('merchant')->middleware(MerchantAppAuth::class)->group(function () {

    // 问题反馈进度列表
    Route::get('feedbackProgressLists', [ProblemFeedbackController::class, 'feedbackProgressLists']);

    // 问题反馈进度详情
    Route::get('feedbackProgressDetail/{workOrderNo}', [ProblemFeedbackController::class, 'feedbackProgressDetail']);
    // 问题反馈进度详情V2
    Route::get('feedbackProgressDetailV2/{workOrderNo}', [ProblemFeedbackController::class, 'feedbackProgressDetailV2']);

    //添加问题工单
    Route::post('addWorkOrder', [ProblemFeedbackController::class, 'addWorkOrder'])
         ->middleware([
             LockBefore::class . ":" . LockBefore::LOCK_TYPE_MERCHANT_USER_ID . ':1',
             LockAfter::class . ':' . LockBefore::LOCK_TYPE_MERCHANT_USER_ID
         ]);

    //获得问题反馈列表
    Route::get('getProblemList', [ProblemFeedbackController::class, 'problemList']);
    //问题表单分类信息
    Route::get('problemType', [ProblemFeedbackController::class, 'problemType']);

    //根据参数判断表单类型（样式）
    Route::get('getProblemForm', [ProblemFeedbackController::class, 'getProblemForm']);
    Route::get('getProblemDetail/{workOrderNo}', [ProblemFeedbackController::class, 'getProblemDetail']);

    // 问题反馈顶部消息提示
    Route::get('topTips', [ProblemFeedbackController::class, 'topTips']);


    Route::prefix("functionOpen")->group(function () {
        Route::get("preview", [FunctionOpenController::class, "preview"]);//功能开通预览
        Route::get("formContent", [FunctionOpenController::class, "formContent"]);//功能开通表单
        Route::put("saveField", [FunctionOpenController::class, "saveField"]);//功能开通字段保存 - 废弃
        Route::put("saveFields", [FunctionOpenController::class, "saveFields"]);//功能开通多字段保存
        Route::put("submitForm", [FunctionOpenController::class, "submitForm"]) //功能开通表单提交
             ->middleware([
            LockBefore::class . ":" . LockBefore::LOCK_TYPE_MERCHANT_USER_ID . ':1',
            LockAfter::class . ':' . LockBefore::LOCK_TYPE_MERCHANT_USER_ID
        ]);
        Route::get("fyRegionBank", [FunctionOpenController::class, "fyRegionBank"]); //区域银行
    });

    // 获得工单V2详情
    Route::get('getWorkOrderV2/{value}', [ProblemFeedbackController::class, 'getWorkOrderV2'])->where('value', "[0-9]+");
    // 提交工单
    Route::post('stepSubmitWorkOrderV2/{id}', [ProblemFeedbackController::class, 'stepSubmitWorkOrderV2'])->where('id', "[0-9]+");
    Route::post('submitWorkOrderV2/{id}', [ProblemFeedbackController::class, 'submitWorkOrderV2'])
        ->middleware([
            LockBefore::class . ":" . LockBefore::LOCK_TYPE_MERCHANT_USER_ID . ':2',
            LockAfter::class . ':' . LockBefore::LOCK_TYPE_MERCHANT_USER_ID
        ])->where('id', "[0-9]+");


    Route::prefix("mission")->group(function () {
        Route::get("pressNotice/{workOrderNo}", [MissionController::class, "pressNotice"]);//一键催办
    });

    Route::prefix("recognize")->group(function () {
        Route::post("/identityCard", [UserBaseInfoController::class, "identityCardRecognize"]);//身份证识别
        Route::post("/publicIdentityCard", [UserBaseInfoController::class, "publicIdentityCardRecognize"]);//身份证识别
        Route::post("/businessLicense", [UserBaseInfoController::class, "businessLicenseRecognize"]);//营业执照识别
        Route::post("/foodBusinessLicense", [CommonController::class, "foodProduceLicenseRecognize"]);//食品经营许可证识别
        Route::post("/bankCard", [CommonController::class, "recognizeBankCard"]);//银行卡识别
        Route::post('/socialSecurityCard', [CommonController::class, 'recognizeSocialSecurityCard']);//社保卡识别
    });
    // 富友微信/支付宝渠道认证确认
    Route::get('channelAuthorize/{workOrderNo}', [FunctionOpenController::class, 'getChannelAuthorize']);
    Route::post('channelAuthorize/{workOrderNo}', [FunctionOpenController::class, 'channelAuthorize']);

    //评价反馈
    Route::prefix("appraise")->group(function () {
        Route::post("/add", [AppraiseController::class, "add"]);//发布评价
        Route::get("/config", [AppraiseController::class, "config"]);//获取评价对应内容配置
        Route::get("/info/{id}", [AppraiseController::class, "info"])->where('id', '[0-9]+');//查看评价详情
        Route::get("/getNewConfig", [AppraiseController::class, "getNewConfig"]);//获取评价对应内容配置-new
        Route::get("/info", [AppraiseController::class, "getInfoByOrderNo"]);//查看评价详情-通过订单号
    });

    Route::post('merchantConfirmFinish/{workOrderNo}',
        [\App\Http\Controllers\WorkOrder\Merchant\WorkOrderController::class, 'merchantConfirmFinish']);

    // 选品建议
    Route::prefix('productSelectionProposal')->group(
        function () {
            Route::get('/getForm', [ProductSelectionProposalController::class, 'getForm']); // 获取表单
            Route::get('/getSubmitNum', [ProductSelectionProposalController::class, 'getSubmitNum']); // 获取提交次数
            Route::post('/submitForm', [ProductSelectionProposalController::class, 'submitForm']);// 提交表单
            Route::get('/lists', [ProductSelectionProposalController::class, 'lists']);// 获取历史提交记录
            Route::get('/detail/{workOrderNo}', [ProductSelectionProposalController::class, 'detail']);// 通过工单号获取详情
        }
    );

});

// web端后台路由
Route::prefix('web')->middleware([
    FeishuWebAuth::class,
    UserPermissionAuth::class . ':' . UserPermissionAuth::MODULE_WORK_ORDER
])->group(function () {

    //根据工单号获取Web端工单信息
    Route::get('getWorkOrderInfoByNo', [ProblemFeedbackWebController::class, 'getWorkOrderInfoByNo']);

    //修改工单
    Route::get('updateWorkOrder', [ProblemFeedbackWebController::class, 'updateWorkOrder']);

    // 工单池列表
    Route::get('orderLists', [WorkOrderController::class, 'orderLists']);

    // 工单池数字看板
    Route::get('orderPanel', [WorkOrderController::class, 'orderPanel']);

    // 工单驳回
    Route::post('reject/{workOrderNo}', [WorkOrderController::class, 'reject']);

    // 抢单
    Route::post('grabOrder/{workOrderNo}', [WorkOrderController::class, 'grabOrder'])
         ->middleware([
             LockBefore::class . ":" . LockBefore::LOCK_TYPE_WEB_USER_ID,
             LockAfter::class . ':' . LockBefore::LOCK_TYPE_WEB_USER_ID
         ]);

    // 工单转交
    Route::post('transfer', [WorkOrderController::class, 'transfer'])
         ->middleware([
             LockBefore::class . ":" . LockBefore::LOCK_TYPE_WEB_USER_ID,
             LockAfter::class . ':' . LockBefore::LOCK_TYPE_WEB_USER_ID
         ]);

    Route::prefix("apply")->group(function () {
        Route::get('shopImg', [ApplyController::class, 'shopImg']);//获取门店套图列表
        Route::put("shopImg/{id}", [ApplyController::class, "updateShopImg"]);//修改门店套图列表
        Route::get("main/{workOrderNo}", [ApplyController::class, "mainDetail"]);//申请详情
        Route::get("content/{workOrderNo}", [ApplyController::class, "contentDetail"]);//申请详情
        Route::get("missionNotice/{workOrderNo}", [MissionController::class, "missionNotice"]);//一键催办
        Route::put("updatePriority/{workOrderNo}", [ApplyController::class, "updatePriority"]);//修改优先级
        Route::put("updateShopMobile/{workOrderNo}", [ApplyController::class, "updateShopMobile"]);//修改门店手机号
        Route::put("submitRemarkAndSolution/{workOrderNo}",
            [ApplyController::class, "submitRemarkAndSolution"]);//提交备注｜解决方案
        Route::put("closeWorkOrder/{workOrderNo}", [ApplyController::class, "closeWorkOrder"]);//关闭工单
        Route::put("closeWorkOrderV2/{workOrderNo}", [ApplyController::class, "closeWorkOrderV2"]);//关闭工单
        Route::post("renew/{workOrderNo}", [ApplyController::class, "renew"]); //修改工单
        Route::post("circulation/{workOrderNo}", [ApplyController::class, "circulation"]); //工单转交

        Route::get("fyRegionBank", [FunctionOpenController::class, "fyRegionBank"]); //功能开通表单提交
        Route::post('fuyouInfo', [ApplyController::class, 'addFuyouInfo']);//富友进件2.0-新增富友信息
        Route::put('fuyouInfo/{id}', [ApplyController::class, 'updateFuyouInfo']);//富友进件2.0-修改富友信息
        Route::post('sendFuyouEmail/{id}', [ApplyController::class, 'sendFuyouEmail']);//富友进件2.0-重新发送邮件

        Route::put("submitRemark/{workOrderNo}", [ApplyController::class, "submitRemark"]);//提交备注
        Route::put("submitSolution/{workOrderNo}", [ApplyController::class, "submitSolution"]);//提交解决方案
        Route::put("submit/{workOrderNo}", [ApplyController::class, "submit"]);//提交至下一阶段
    });

    Route::prefix("recognize")->group(function () {
        Route::post("/identityCard", [UserBaseInfoController::class, "identityCardRecognize"]);//身份证识别
        Route::post("/businessLicense", [UserBaseInfoController::class, "businessLicenseRecognize"]);//营业执照识别
        Route::post("/foodBusinessLicense", [CommonController::class, "foodProduceLicenseRecognize"]);//营业执照识别
        Route::post("/bankCard", [CommonController::class, "recognizeBankCard"]);//银行卡识别
        Route::post('/socialSecurityCard', [CommonController::class, 'recognizeSocialSecurityCard']);//社保卡识别
    });
    // 生成资料zip包下载URL
    Route::get('download/zipUrl', 'Web\\DownloadController@zipUrl');

    //评价反馈
    Route::prefix("appraise")->group(function () {
        Route::get("/lists", [WebAppraiseController::class, "lists"]);//评价列表
        Route::get("/info/{id}", [WebAppraiseController::class, "info"])->where('id', '[0-9]+');//评价详情
        Route::post("/add/{id}", [WebAppraiseController::class, "addReply"])->where('id', '[0-9]+');//评价回复备注
        Route::put("/update/{id}", [WebAppraiseController::class, "update"])->where('id', '[0-9]+');//评价完成
        Route::get("/config", [WebAppraiseController::class, "config"]);//获取评价对应内容配置
        Route::get("/getNewConfig", [WebAppraiseController::class, "getNewConfig"]);//获取评价对应内容配置-new
    });

    // 重置功能开通
    Route::post('resetFunctionOpen', [ApplyController::class, 'resetFunctionOpen']);

    Route::prefix("form")->group(function () {
        Route::get("/type", [WorkOrderController::class, 'type']);//表单分类选择
        Route::get('/problemForm', [ProblemFeedbackController::class, 'getBackendProblemForm']);
        //添加问题工单
        Route::post('problemFormAdd', [ProblemFeedbackController::class, 'backendAddProblemWorkOrder']);
    });

    // 选品建议
    Route::prefix('productSelectionProposal')->group(
        function () {
            Route::get('/lists', [ProductSelectionProposalWebController::class, 'lists']);                 // 选品建议列表
            Route::get('/detail/{workOrderNo}', [ProductSelectionProposalWebController::class, 'detail']); // 通过工单号获取详情
            Route::post('/update/{workOrderNo}', [ProductSelectionProposalWebController::class, 'update']);// 通过工单号修改状态
        }
    );

    // 工单分类管理
    Route::prefix('type')->group(function () {
        // 分类列表
        Route::get('list', [WorkflowV2TypeController::class, 'list']);
        // 添加&编辑分类
        Route::post('save', [WorkflowV2TypeController::class, 'save']);
        // 启用停用
        Route::post('/updateStatus/{id}', [WorkflowV2TypeController::class, 'updateStatus'])->where('id', '[0-9]+');
        // 删除分类
        Route::delete('/{id}', [WorkflowV2TypeController::class, 'delete'])->where('id', '[0-9]+');

    });

});
// 去下载资料zip包
Route::get('web/download/zipFile', 'Web\\DownloadController@zipFile');


// 通用
Route::prefix('common')->group(function () {
    //根据订单获取商品信息
    Route::get('getOrmOrderGoods', [ProblemFeedbackController::class, 'getOrmOrderGoods']);
});

// 富有自动进件-test
Route::prefix('fuyou')->group(function () {
    //4.1 商户信息登记接口
    Route::get('/', [FuYouController::class, 'index']);
});
